package com.net.xpay.common.manager.impl.stat;

import com.google.common.base.Preconditions;
import com.net.xpay.common.manager.stat.UserSafePayTransMonthStatManager;
import com.net.common.dao.BasicMapper;
import com.net.common.dao.Page;
import com.net.xpay.common.dao.stat.UserSafePayTransMonthStatMapper;
import com.net.xpay.common.domain.stat.UserSafePayTransMonthStat;
import com.net.common.manager.AbstractManager;
import com.net.xpay.core.model.UserSafePayTransMonthStatSearchModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.List;


@Component
public class UserSafePayTransMonthStatManagerImpl extends AbstractManager<UserSafePayTransMonthStat> implements UserSafePayTransMonthStatManager {

    @Autowired
    private UserSafePayTransMonthStatMapper mapper;


    @Override
    protected BasicMapper<Long, UserSafePayTransMonthStat> getMapper() {
        return mapper;
    }

    @Override
    public UserSafePayTransMonthStat findByMonthOfYear(Integer year, Integer month, Long userId) {
        Preconditions.checkArgument(year != null && month != null && userId != null);
        UserSafePayTransMonthStat condition = new UserSafePayTransMonthStat();
        condition.setYear(year);
        condition.setMonth(month);
        condition.setUserId(userId);
        return getByCondition(condition);
    }

    @Override
    public List<UserSafePayTransMonthStat> search(UserSafePayTransMonthStatSearchModel searchModel) {
        Preconditions.checkArgument(searchModel != null);
        Page page = new Page(searchModel);
        page.addOrder("id", "desc");
        return nonEmptyList(mapper.search(searchModel, page));
    }

    @Override
    public long searchCount(UserSafePayTransMonthStatSearchModel searchModel) {
        Preconditions.checkArgument(searchModel != null);
        return mapper.searchCount(searchModel);
    }

    @Override
    public List<UserSafePayTransMonthStat> list(UserSafePayTransMonthStatSearchModel searchModel) {
        Preconditions.checkArgument(searchModel != null);

        return nonEmptyList(mapper.list(searchModel));
    }
}
